extension :sources => :copy_update do
  use :sources => :checkout

  task :sources do
    build_repository.setup!
    rev = build_repository.revisions.reverse.find { |r| r < real_revision && build_repository[r].checked_out }
    if rev == nil
      logger.info "can't find any suitable revision to update. falling back to fresh checkout"
      execute_previous # will execute checkout due to the 'use' definition in the beginning
    else
      brev = build_repository[real_revision]
      brev.setup!
      FileUtils.rm_rf(brev.src_path)
      FileUtils.cp_r(build_repository[rev].src_path, brev.src_path)
      syscmd scm.sync(real_revision, brev.src_path)
    end 
  end
end
